#include <iostream>
#include <vector>
#include <unordered_map>

using std::vector;
using std::unordered_map;

class RandomizedSet {
public:
    RandomizedSet() {
        srand((unsigned)time(NULL));
    }

    bool insert(int val) {
        if (map.count(val)) {
            return false;
        }
        int index = v.size();
        v.emplace_back(val);
        map.emplace(val, index);
        return true;
    }

    bool remove(int val) {
        if (!map.count(val)) {
            return false;
        }
        int index = map[val];
        v[index] = v.back();
        map[v.back()] = index;
        v.pop_back();
        map.erase(val);
        return true;
    }

    int getRandom() {
        return v[rand() % v.size()];
    }
private:
    vector<int> v;
    unordered_map<int, int> map;
};